﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfTravelIndex1 : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
            }
        }
        private void BindControls()
        {
            if (!IsPostBack)
            {
            }
        }

        private void getArea2(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                StringBuilder selectData = new StringBuilder();
                selectData.Append(@"[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        selectData.Append(",");
                    }
                    string tempData = @"{""ID"":""$ID$"",""Name"":""$Name$""}";
                    tempData = tempData.Replace("$ID$", ds.Tables[0].Rows[i]["COUNTRY_CITY_ID"].ToString());
                    tempData = tempData.Replace("$Name$", ds.Tables[0].Rows[i]["COUNTRY_CITY_NME"].ToString());
                    selectData.Append(tempData);
                }
                selectData.Append(@"]");
                string cityId = this.GetParamHtValue("cityId");
                this.ExecJScript(@"selectArea('secendArea'," + selectData.ToString() + ",'" + cityId + "');");
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                getArea3(cityId);
            }
        }
        private void getArea3(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                StringBuilder selectData = new StringBuilder();
                selectData.Append(@"[");
                string isAll = this.GetParamHtValue("isAll");
                if (isAll.ToLower() == "true")
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["COUNTRY_CITY_ID"] = "";
                    dr["COUNTRY_CITY_NME"] = "全部";
                    ds.Tables[0].Rows.InsertAt(dr, 0);
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        selectData.Append(",");
                    }
                    string tempData = @"{""ID"":""$ID$"",""Name"":""$Name$""}";
                    tempData = tempData.Replace("$ID$", ds.Tables[0].Rows[i]["COUNTRY_CITY_ID"].ToString());
                    tempData = tempData.Replace("$Name$", ds.Tables[0].Rows[i]["COUNTRY_CITY_NME"].ToString());
                    selectData.Append(tempData);
                }
                selectData.Append(@"]");
                string destionId = this.GetParamHtValue("destionId");
                this.ExecJScript(@"selectArea('area'," + selectData.ToString() + ",'" + destionId + "');");
               
            }
        }
        private void initplace(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                StringBuilder selectData = new StringBuilder();
                selectData.Append(@"[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        selectData.Append(",");
                    }
                    string tempData = @"{""ID"":""$ID$"",""Name"":""$Name$""}";
                    tempData = tempData.Replace("$ID$", ds.Tables[0].Rows[i]["COUNTRY_CITY_ID"].ToString());
                    tempData = tempData.Replace("$Name$", ds.Tables[0].Rows[i]["COUNTRY_CITY_NME"].ToString());
                    selectData.Append(tempData);
                }
                selectData.Append(@"]");
                string countryId = this.GetParamHtValue("countryId");
                this.ExecJScript(@"selectArea('topArea'," + selectData.ToString() + ",'" + countryId + "');");
                if (string.IsNullOrEmpty(countryId))
                {
                    countryId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                getArea2(countryId);
            }
        }

        private void GetClassicScenic(string destionId, string cityId, string countryId)
        {
            using (msBsc.AppLogic.DataAlc.CBizPushScenic scenic = new AppLogic.DataAlc.CBizPushScenic())
            {
                DataSet ds = scenic.GetScenicForPageview(4, 1, destionId, cityId, countryId);
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 20, "");
                //StringBuilder strJson = new StringBuilder();
                //strJson.Append(@"[");
                //string temp = @"{""scenicId"":""$scenicId$"",""scenicName"":""$scenicName$"",""scenicPic"":""$scenicPic$""}";
                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    if (i > 0)
                //    {
                //        strJson.Append(@",");
                //    }
                //    string scenicInfo = temp;
                //    scenicInfo = scenicInfo.Replace("$scenicId$", ds.Tables[0].Rows[i]["SCENIC_ID"].ToString());
                //    scenicInfo = scenicInfo.Replace("$scenicName$", ds.Tables[0].Rows[i]["SCENIC_Name"].ToString());
                //    scenicInfo = scenicInfo.Replace("$scenicPic$", ds.Tables[0].Rows[i]["SCENIC_DEFAULT_PIC"].ToString());
                //    strJson.Append(scenicInfo);
                //}
                //strJson.Append(@"]");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_scenic').html();
                            laytpl(_html).render(" + strJson.ToString()+@", function (render) {
                                $('#scenicList').append(render);
                            });");
            }
        }

        private void GetClassicFood(string destionId, string cityId, string countryId)
        {
            using (msBsc.AppLogic.DataAlc.CBizPushNiceFood food = new AppLogic.DataAlc.CBizPushNiceFood())
            {
                DataSet ds = food.GetNiceFoodForPageview(4, 1, destionId, cityId, countryId);
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 20, "");
                //StringBuilder strJson = new StringBuilder();
                //strJson.Append(@"[");
                //string temp = @"{""scenicId"":""$scenicId$"",""scenicName"":""$scenicName$"",""scenicPic"":""$scenicPic$""}";
                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    if (i > 0)
                //    {
                //        strJson.Append(@",");
                //    }
                //    //DATACOUNT
                //    string scenicInfo = temp;
                //    scenicInfo = scenicInfo.Replace("$scenicId$", ds.Tables[0].Rows[i]["NICEFOOD_ID"].ToString());
                //    scenicInfo = scenicInfo.Replace("$scenicName$", ds.Tables[0].Rows[i]["NICEFOOD_NAME"].ToString());
                //    scenicInfo = scenicInfo.Replace("$scenicPic$", ds.Tables[0].Rows[i]["NICEFOOD_DEFAULT_PIC"].ToString());
                //    strJson.Append(scenicInfo);
                //}
                //strJson.Append(@"]");
                this.ExecJScript(@"
                                            var _html = $('#svc_list_tem_food').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                                $('#foodList').append(render);
                            });");
            }
        }

        private void GetClassicSpecialty(string destionId, string cityId, string countryId)
        {
            using (msBsc.AppLogic.DataAlc.CBizPushSpecialty specialty = new AppLogic.DataAlc.CBizPushSpecialty())
            {
                DataSet ds = specialty.GetSpecialForPageview(4, 1, destionId, cityId, countryId);
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 20, "");
                this.ExecJScript(@"
                                            var _html = $('#svc_list_tem_specialty').html();
                                            laytpl(_html).render(" + strJson + @", function (render) {
                                                $('#specialtyList').append(render);
                                            });");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "getClassic")
            {
                DateTime dttem = System.DateTime.Now;
                string parentsId = this.GetParamHtValue("parentsId");
                initplace(parentsId);
                string countryId = this.GetParamHtValue("countryId");
                string cityId = this.GetParamHtValue("cityId");
                string destionId = this.GetParamHtValue("destionId");
                GetClassicScenic(destionId, cityId, countryId);
                GetClassicFood(destionId, cityId, countryId);
                GetClassicSpecialty(destionId, cityId, countryId);
            }
            else if (this.strAction == "getCity")
            {
                string countryId = this.GetParamHtValue("countryId");
                using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
                {
                    DataSet ds = cbcc.SelectCountryByParentId(countryId);
                    
                    string cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                    this.ExecJScript(@"window.location.href ='/wp_TravelIndex.htm?countryId=" + countryId + "&cityId=" + cityId + "&destionId=&pIndex=1'");
                }
            }
            else if (this.strAction == "getScenic")
            {
                string countryId = this.GetParamHtValue("countryId");
                string cityId = this.GetParamHtValue("cityId");
                string destionId = this.GetParamHtValue("destionId");
                GetClassicScenic(destionId, cityId, countryId);
                //GetClassicFood(destionId, cityId, countryId);
                //GetClassicSpecialty(destionId, cityId, countryId);
            }
        }
    }
}